feat(node): Only setup orchestrion channel listeners when needed#22312
feat(node): Only setup orchestrion channel listeners when needed#22312mydea wants to merge 10 commits into
Conversation
|
|
||
| const BUNDLER_MARKER_BANNER = | ||
| ';(globalThis.__SENTRY_ORCHESTRION__=(globalThis.__SENTRY_ORCHESTRION__||{})).bundler=true;'; | ||
| ';(globalThis.__SENTRY_ORCHESTRION__=(globalThis.__SENTRY_ORCHESTRION__||{})).bundler=[];'; |
There was a problem hiding this comment.
cc @isaacs do we actually need this? Can we properly inject this with the correct modules somehow?
size-limit report 📦
|
| */ | ||
| export function getOrchestrionInjectedModules(): string[] { | ||
| const { runtime, bundler } = GLOBAL_OBJ.__SENTRY_ORCHESTRION__ ?? {}; | ||
| return [...(runtime ?? []), ...(bundler ?? [])]; |
There was a problem hiding this comment.
q: Do we care about potential duplicates? Probably not, as this is for now used anyways just for modules.includes(name)
| export const fastifyIntegration = defineIntegration((options: Partial<FastifyIntegrationOptions> = {}) => | ||
| _fastifyIntegration(options), | ||
| ); | ||
| export const fastifyIntegration = defineIntegration(_fastifyIntegration); |
There was a problem hiding this comment.
q: Just for my understanding, not to miss anything. The Fastify changes are unrelated theoretically right?
Ok to land here, since they are small changes 🤏
There was a problem hiding this comment.
yeah just noticed this unnecessary wrapper here :)
| @@ -0,0 +1,78 @@ | |||
| import * as diagnosticsChannel from 'node:diagnostics_channel'; | |||
There was a problem hiding this comment.
q: The PR description states it was meant only for Express. Was Kafka and GraphQL intended to be in here too?
Implementation looks fine though
There was a problem hiding this comment.
PR description is inclomplete, I actually moved everything now :)
| const subscribers: Partial<TracingChannelSubscribers<ConsumerRunChannelContext>> = { | ||
| start(ctx) { | ||
| const config = ctx.arguments[0]; | ||
| if (!config || typeof config !== 'object') { |
There was a problem hiding this comment.
l: We could use the new isObjectLike helper
There was a problem hiding this comment.
I did not change this here, just moved it - we can/should update this in a follow up I'd say :)
acd44ec to
cd1e0f9
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9b33e48. Configure here.

This PR implements a way to lazy-load orchestrion instrumentation (runtime code) only when something was actually wrapped.
setupOncewe look at the list of instrumented modules, and only run the instrumentation if something was already orchestrion-wrappedsetupwe add a listener to a client hook event which is emitted whenever something is runtime-wrapped by orchestrion. There we check if a module was wrapped that we need, and if so, we add the instrumentation, listening to the respective channels.Other Runtimes (Deno, Bun)
In Deno and Bun we do not have the concrete list of build-time instrumented things (yet). However, the limits of channel registrations also do not really apply there - so this PR just registers everything immediately there. We can revisit this later.
Next.js
This needs adjustments for turbopack...
Closes #22302